function limpiar(id) {
  if (id == "reproductor") {
    document.getElementById("enlaces").style.display = "block";
    document.getElementById(id).innerHTML = "";
  }
  if (id == "enlaces") {
    document.getElementById("index").style.display = "block";
    document.getElementById(id).innerHTML = "";
  }
}
function abrirenlaces(argument) {
  document.getElementById("index").style.display = "none";
  if (!document.getElementById("enl")) {
    create = document.createElement("ul");
    create.id = "enl";
    create.setAttribute("class", "enl");
    document.getElementById("enlaces").appendChild(create);
    var enlaces = argument.split(",");
    for (var i = 0;i < enlaces.length;i++) {
      idioma = "e" == enlaces[i].substr(0, 1) ? "Espa\u00f1ol / " : "Latino / ";
      enl = enlaces[i].substr(1);
      dom = enl.match(/(([a-zA-Z0-9\-]{0,65}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}/igm);
      create.innerHTML += "<li onclick='send_with_ajax(\"http://allmyvideos.net/embed-" + enl.split("/")[3] + ".html\")'>" + idioma + dom + "</li>";
    }
    document.getElementById("enlaces").innerHTML += "<a href='javascript:limpiar(\"enlaces\")'>atras</a>";
  }
}
function hola(data) {
  ulcreate = document.createElement("ul");
  ulcreate.id = "hola";
  ulcreate.setAttribute("class", "items");
  document.getElementById("index").appendChild(ulcreate);
  for (var i = 0;i < data.feed.entry.length;i++) {
    root = data.feed.entry[i];
    enlaces = root.gsx$enlaces.$t.replace(/ /g, "");
    ulcreate.innerHTML += "<li onclick='abrirenlaces(\"" + enlaces + "\")'><img width='40' src='" + root.gsx$imagen.$t.replace(".jpg", "-thumb.jpg") + "'></img><span class='meta'><a href='#'>" + root.title.$t + "</a><br/>Genero y Calidad: " + root.gsx$genero.$t + root.gsx$calidad.$t + "</span></li>";
  }
}
function alertContents(httpRequest) {
  if (httpRequest.readyState == 4) {
    if (httpRequest.status == 200 || httpRequest.status == 0) {
      document.getElementById("enlaces").style.display = "none";
      if (!document.getElementById("reproductor").getElementsByTagName("video")[0]) {
        var htmlsource = httpRequest.responseText;
        var video = document.createElement("video");
        var imgvid = htmlsource.match(/https?:\/\/([a-z0-9]+[.])*allmyvideos[.]net\/i\/[A-Za-z0-9-_:%&~\?\/.=]+/g);
        var urlvid = htmlsource.match(/https?:\/\/([a-z0-9]+[.])*allmyvideos[.]net\/d\/[A-Za-z0-9-_:%&~\?\/.=]+/g);
        video.src = "undefined" == urlvid[1] ? urlvid[1] : urlvid[0];
        video.poster = imgvid[0];
        video.type = "video/mp4";
        video.controls = true;
        document.getElementById("reproductor").appendChild(video);
        document.getElementById("reproductor").innerHTML += "<p><a href='javascript:limpiar(\"reproductor\")'>atras</a></p>";
      }
    } else {
      document.getElementById("reproductor").innerText = "There was a problem with the request. " + httpRequest.status + httpRequest.responseText;
    }
  }
}
function send_with_ajax(the_url) {
  var httpRequest = new XMLHttpRequest;
  httpRequest.onreadystatechange = function() {
    alertContents(httpRequest);
  };
  httpRequest.open("GET", the_url, true);
  httpRequest.send(null);
}
;